﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Twittit.Web
{
    public partial class Follow : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Twittit.DataAccess.User currentUser = new DataAccess.User();
            Twittit.Business.UserService t = Twittit.Business.UserService.getInstance();
            if (Request.QueryString["user"] == null && Session["username"] == null)
                this.Response.Redirect("Login.aspx");

            if (Session["username"] != null && Request.QueryString["user"] == null)
                currentUser = t.getUserByUsername(Session["username"].ToString());
            else
            {                
                int userRequestedId = Convert.ToInt32(Request.QueryString["user"].ToString());
                currentUser = t.getUserByID(userRequestedId);
            }           
           
            UserSubscribersRepeater.DataSource = t.getSubscribers(currentUser.id);
            UserSubscribersRepeater.DataBind();
            TitleSubscribersLabel.Text = currentUser.twittit;
            int countSubscribers = t.countSubscribers(currentUser.id);
            CountSubscribersLabel.Text = countSubscribers.ToString();
            if (countSubscribers > 1)
                PersSubscribersLabel.Text = " personnes";
            else
                PersSubscribersLabel.Text = " personne";

            UserSubscribingRepeater.DataSource = t.getSubscribed(currentUser.id);
            UserSubscribingRepeater.DataBind();
            TitleSubscribingLabel.Text = currentUser.twittit;
            int countSubscribing = t.countSubscribed(currentUser.id);
            CountSubscribingLabel.Text = countSubscribing.ToString();
            if (countSubscribing > 1)
                PersSubscribingLabel.Text = " personnes";
            else
                PersSubscribingLabel.Text = " personne";

            UserIDLabel.Text = currentUser.id.ToString();
            TwittitLabel.Text = currentUser.twittit;
            TitleLabel.Text = currentUser.twittit;
            NameLabel.Text = currentUser.name;
            MailLabel.Text = currentUser.email;
            WebsiteLabel.Text = currentUser.website;
            LocalisationLabel.Text = currentUser.localisation;
            AboutLabel.Text = currentUser.aboutyou;
            inDateLabel.Text = currentUser.inDate.ToString("dd/MM/yyyy");

            UserGravatar.Email = currentUser.email;
        }
    }
}